/* *********
 *    Author: Jason He;
 *    Version: 0.0.1;
 *    Date: 2016-12-26;
 *    File: list-brand.js;
 ********* */

$(document).ready(function () {
	$(".letter-item").click(function () {
		var id = $(this).attr("id");
		var scrollTop = $("#" + id).offset().top;
		$("body").scrollTop(scrollTop);
	});

	var scrollTop = 0;
	$(window).scroll(function () {
		scrollTop = $(window).scrollTop();
		maxTop = $("#all").offset().top + 26;

		if (scrollTop >= maxTop) {
			$("#letter").addClass("fixed");
		} else {
			$("#letter").removeClass("fixed");
		}

		$("#series").hide();
	});

	$(".brand-item").click(function () {
	    var bdid = $(this).attr('bdkey');
	    var bdtxt = $.trim($(this).text());
	    $('#brand-name').text(bdtxt);
	    $('#brand-logo').attr('src', $('#brand-logo').attr("bdimgdir") + bdid + ".png");
	    
		$.ajax({
		    url: "/public/uploads/js/brandsubseries" + bdid + ".json",
			dataType: "json",
			success: function (rls) {
				var top = 44 - $(window).scrollTop();
				if (top > 0) {
					$("#series").css({"top": top, "height": $(window).height() - top});
				} else {
					$("#series").css({"top": 0, "height": "100%"});
				}
				var html = '<li>';
				html += '<a href="javascript:jumpUrl(\'se\',\'\')">不限车系</a>';
				html += '</li>';
				var data = rls["Data"];
				for (var i = 0; i < data.length; i++) {
					html += '<li>';
					html += '<a href="javascript:jumpUrl(\'se\',\'' + data[i].sn + '\')">';
					html += '<img src="/Theme/app/img/icon.png">';
				    //html += '<p>' + data[i].sn + '<span>约' + data[i].st + '辆</span></p>';
					html += '<p>' + data[i].sn + '</p>';
					html += '</a>';
					html += "</li>";
				}
				$("#series-list").html(html);
				$("#series").show()
			}
		});
	});

	document.getElementById("series").onmousewheel = function (event) { 
		if (!event) {
			event = window.event;
		}
		this.scrollTop = this.scrollTop - event.wheelDelta;
		return false; 
	}
});